package com.tianya.common.util;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

public class AuthFilter implements Filter {

	public void destroy() {

	}
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
			FilterChain filterChain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest)servletRequest; 
		HttpServletResponse response = (HttpServletResponse) servletResponse;
		String currentURL = request.getRequestURI().toLowerCase(); // 取得根目录所对应的绝对路径: 
		//HttpSession session = request.getSession(false); 
		
		//拦截器JSP如果是action则由Authority处理
		if(currentURL.endsWith(".jsp")){
	/*		if(session == null || session.getAttribute(SessionConst.User) == null ){ 
			  String strAcion =  DefaultSettings.get("struts.action.extension");
			  String login = DefaultSettings.get("struts.action.login");
			  if(Utility.isEmpty(strAcion)){
				  strAcion = "\\login.action";
			  }else{
				  strAcion = "\\login." + 
			  }
	          response.sendRedirect(request.getContextPath()+"\\login.jsp"); 
	          return ; 
	       } */
			//
			if(currentURL.endsWith("login")|| currentURL.endsWith("loginuser")|| currentURL.endsWith("external") ||currentURL.endsWith("safecode")){
				
			}else{
		        // 判断当前页是否是重定向以后的登录页面页面，如果是就不做session的判断，防止出现死循环 
		       
		    } 
		}
		
	    // 加入filter链继续向下执行 
	    filterChain.doFilter(request, response); 

	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub

	}

}
